package main

import (
	"encoding/json"
	"github.com/gin-gonic/gin"
	"net/http"
)

type ReturnValue struct {
	Code    string      `json:"code"`
	Message string      `json:"msg,omitempty"`
	Format  string      `json:"fmt,omitempty"`
	Data    interface{} `json:"data,omitempty"`
}

func Return_ok_result(c *gin.Context, code, msg string, data interface{}) {
	v := &ReturnValue{
		Code:    code,
		Message: msg,
	}
	if data != nil {
		v.Data = data
	}
	dd, _ := json.Marshal(v)
	c.String(http.StatusOK, string(dd))
}

func Return_params_error_result(c *gin.Context, err error) {
	Return_ok_result(c, "1000", err.Error(), nil)
}

func Return_sign_verification_result(c *gin.Context, bVerified bool) {
	v := &ReturnValue{
		Code: "0000",
	}

	if !bVerified {
		v.Code = "0002"
		v.Message = "签名验签失败"
	} else {
		v.Code = "0000"
		v.Message = "签名验签成功"
	}

	c.JSON(http.StatusOK, v)
}
